<?php
namespace Lsf\Factory;

/**
 * Zookeeper工厂类
 * @author lichenkai@okay.cn
 * $Id: zookeeper.php 2019-08-05 14:43:17 lichenkai $
 */

class Zookeeper
{
    static protected $zookeeper = [];

    static public function getInstance($key = 0, $singleton = TRUE){
        if($singleton === FALSE || empty(self::$zookeeper[$key])){
            $config = \Lsf\Loader::config('zookeeper', TRUE, 2);
            if(!isset($config['host']) || empty($config['host'])){
                throw new \Exception('Config zookeeper host param invalid');
            }else{
                $class = '\\Lsf\\Client\\Zookeeper';
                $zookeeper = new $class($config['host']);
                if($singleton === TRUE){
                    self::$zookeeper[$key] = $zookeeper;
                }
                return $zookeeper;
            }
        }
        return self::$zookeeper[$key];
    }
}